home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / gestalt.zip / GESTALT.ASM < prev    next >
Assembly Source File  |  1988-12-06  |  3KB  |  112 lines

  1. ;Test program for SIMIL_A.ASM string comparison function.
  2. ;Relatively complete explanation there, or read the original article
  3. ;in Dr. Dobbs Journal.
  4. ;
  5. ;My stuff released to public domain, original authors retain
  6. ;any copyright, etc. (though none was indicated).
  7. ;
  8. ;David Kirschbaum
  9. ;Toad Hall
  10. ;kirsch@braggvax.ARPA
  11.  
  12. CR    EQU    0DH
  13. LF    EQU    0AH
  14.  
  15. CSeg    SEGMENT PUBLIC PARA 'CODE'
  16.  
  17. ;WARNING:  This test program ONLY works if SS is in fact CSeg!
  18. ;That kinda blows away .EXE formats, etc. in the present configuration.
  19. ;But this is only a demo, after all ... my fees are $45 an hour
  20. ;if you want anything else...
  21.  
  22.     ASSUME    CS:CSeg, DS:CSeg, ES:CSeg, SS:CSeg
  23.  
  24.     org    100H
  25.  
  26. TestSim    proc    near
  27.     jmp    Start
  28.  
  29.     include    simil_a.asm
  30.  
  31. str1    db    '[20char test string]',0
  32. str2    db    '[20char test string]',0
  33. STRLEN    =    $ - str2        ;string length
  34.  
  35.     db    9,'Similarity: $'
  36. percentmsg db    '%',CR,LF,'$'
  37.  
  38. Start:
  39.     mov    bx,offset str2        ;point to where we'll change string 2
  40.     mov    cx,STRLEN        ;do this for all string 2 chars
  41.  
  42.     mov    si,offset str1        ;first test string (never changes)
  43.     mov    di,offset str2        ;second test string (ditto)
  44.  
  45. Str_Lup:
  46.     mov    dx,si            ;display both strings, 'Similarity'
  47.     mov    ah,9            ;display msg
  48.     int    21H
  49.  
  50.     call    _Simil            ;call our procedure
  51.  
  52.     call    WordWrite        ;display value in AX
  53.  
  54.     mov    byte ptr [bx],'.'    ;overwrite a string 2 char
  55.     inc    bx            ;bump to next blank for next time
  56.  
  57.     mov    dx,offset percentmsg    ;'%', terminating CR/LF
  58.     mov    ah,9
  59.     int    21H
  60.  
  61.     loop    Str_Lup            ;do this for all string 2 chars
  62.  
  63.     mov    ax,4C00H        ;terminate
  64.     int    21H
  65.  
  66. TestSim    endp
  67.  
  68. Display_Int    proc    near
  69. ;from DISKSCAN.ASM, changed a little for this application.
  70.  
  71. divisors    dw    10000, 1000, 100, 10, 1    ; For decimal conversion
  72.  
  73. ;AX contains word to display
  74. WordWrite:
  75.     Push    BX            ;save our char pointer        TH
  76.     Push    CX            ;and our loop counter        TH
  77.     Push    SI            ;and our string pointer        TH
  78.  
  79.     Mov    SI, Offset divisors    ; SI points to divisors
  80.     Mov    CX, 4            ; CL counter; CH zero blanker 
  81.  
  82. WordWriteLoop:
  83.     Mov    BX, [SI]        ; Get divisor 
  84.     Add    SI, 2            ; Increment SI for next one
  85.     Sub    DX, DX            ; Prepare for division
  86.     Div    BX            ; Divide DX:AX by BX
  87.     Push    DX            ; Save remainder
  88.     Or    CH, AL            ; See if zero
  89.     Jz    LeadZero        ; If so, do not display it
  90.      Add    AL, '0'            ; Convert number to ASCII
  91. ;TH     Mov    DL, AL            ; Print out character
  92. ;TH     Mov    AH, 2            ;   by calling DOS
  93. ;TH     Int    21h
  94.      int    29H            ;undocumented quick screen output TH
  95.                     ;reputedly works with all DOS's
  96.                     ;(fer shur with my PC-DOS 3.1
  97. LeadZero:
  98.     Pop    AX            ; Get back remainder
  99.     Dec    CL            ; Decrement counter
  100.     Jg    WordWriteLoop        ; If CL still > 0, do it again
  101.     Mov    CH, 1            ; No more zero blanking
  102.     Jz    WordWriteLoop        ; Convert last digit to ASCII
  103.  
  104.     Pop    SI            ; Get back pushed registers
  105.     Pop    CX
  106.     Pop    BX
  107.     Ret
  108. Display_Int    endp
  109.  
  110. CSeg    ends
  111.     end    TestSim
  112.